#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask import request
from flask_restful import Resource
from common.odooClient import Client

class ResCityListAPI(Resource):
    def get(self):
        odoo = Client.getInstance()
        city_model = odoo.model('res.city')
        if(request.args.get('type') == 'guess'):
            city_ids = city_model.search([('is_guess', '=', True)])
        elif(request.args.get('type') == 'hot'):
            city_ids = city_model.search([('is_hot', '=', True)])
        else:
            city_ids = city_model.search([])
        if city_ids:
            city_list = city_model.read(city_ids, ['id', 'name'])
        else:
            city_list = []
        return {'list': city_list}

class ResCityAPI(Resource):
    def get(self, city_id):
        odoo = Client.getInstance()
        city_model = odoo.model('res.city')
        city_obj = city_model.read(city_id, ['id', 'name'])
        return city_obj